package com.ms.dsq_english.wall

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ms.dsq_english.R
import com.ms.dsq_english.adapter.SalesAdapter
import com.ms.dsq_english.http.HttpManager
import com.ms.dsq_english.model.SalesBean
import com.ms.dsq_english.utils.LogUtils
import com.ms.dsq_english.utils.MapUtilsParamNull
import com.ms.dsq_english.utils.ResultCheckUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.frag_sales.*
import kotlinx.android.synthetic.main.frag_sales.bule
import kotlinx.android.synthetic.main.frag_sales.frg_trs_ccv_clccv_tra
import kotlinx.android.synthetic.main.frag_sales.green
import kotlinx.android.synthetic.main.frag_sales.yellow
import kotlinx.android.synthetic.main.frag_sales.zi
import lecho.lib.hellocharts.model.*
import java.math.BigDecimal
import java.util.*

/**
 * @Description:
 * @Author: zheng
 */
class SalesFragment : Fragment() {

    private lateinit var mContext: Context

    private val list: MutableList<SalesBean.DataBean.SalesRegionBean> = ArrayList()
    private var codeMix = 0
    private var codeXian = 0

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
    {
        mContext = context!!

        return inflater.inflate(R.layout.frag_sales, container, false)
    }

    override fun onResume() {
        super.onResume()
        Glide.with(mContext).load(R.drawable.img_sales_up).into(sales_img)
        sales
        salesQe.setOnClickListener {
            if (sales_rec!!.visibility == View.VISIBLE) {
                sales_imp!!.setImageResource(R.drawable.sales_2)
                sales_rec!!.visibility = View.GONE
            } else {
                sales_rec!!.visibility = View.VISIBLE
                sales_imp!!.setImageResource(R.drawable.sales_1)
            }
        }
        zi.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "江苏省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        bule.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "安徽省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        green.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "河南省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        yellow.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "山东省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        gans1.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "甘肃省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        shanx1.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "陕西省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sanx1.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "山西省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        ningx1.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "宁夏回族自治区") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        guangd1.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "广东省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng1.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "江西省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng2.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "浙江省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng3.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "福建省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng4.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "湖北省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng5.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "四川省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng6.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "贵州省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng7.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "湖南省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng8.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "海南省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng10.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "重庆") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng11.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "天津") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng12.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "内蒙古自治区") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng13.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "黑龙江省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng14.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "吉林省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng15.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "辽宁省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng16.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "河北省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng17.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "北京") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng18.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "青海省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng19.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "广西壮族自治区") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng20.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "云南省") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng21.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "新疆维吾尔自治区") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
        sheng22.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "西藏自治区") {
                    salesNum!!.text = "" + list[i].nums
                }
                i++
            }
        }
    }

    fun refresh() {
        sales
    }

    @get:SuppressLint("CheckResult")
    private val sales: Unit
        private get() {

            val params: HashMap<String, String> = MapUtilsParamNull()
                    .getBaseMap(mContext)

            HttpManager.getRetrofitInterface()
                    .getSales(params)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe({ result: SalesBean ->
                        if (result.code == 10000) {
                            //图表
                            val shopData = result.data.ytD_product_sale_chart
                            initComboLineColumnChartView(shopData)

                            //城市销售
                            if (result.data.city_ranking.size == 7) {
                                val max = result.data.city_ranking_max.toInt()
                                run {
                                    salesCst1.text = result.data.city_ranking[0].cname
                                    val nubxian = result.data.city_ranking[0].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs1.progress = s.toInt()
                                    salesCss1.text = result.data.city_ranking[0].nums
                                    val params = salesCss1.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1469, 630 - d, 0, 0)
                                    salesCss1.layoutParams = params
                                    salesCst1.visibility = View.VISIBLE
                                    salesCs1.visibility = View.VISIBLE
                                    salesCss1.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst2.text = result.data.city_ranking[1].cname
                                    val nubxian = result.data.city_ranking[1].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs2.progress = s.toInt()
                                    salesCss2.text = result.data.city_ranking[1].nums
                                    val params = salesCss2.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1507, 630 - d, 0, 0)
                                    salesCss2.layoutParams = params
                                    salesCst2.visibility = View.VISIBLE
                                    salesCs2.visibility = View.VISIBLE
                                    salesCss2.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst3.text = result.data.city_ranking[2].cname
                                    val nubxian = result.data.city_ranking[2].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs3.progress = s.toInt()
                                    salesCss3.text = result.data.city_ranking[2].nums
                                    val params = salesCss3.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1548, 630 - d, 0, 0)
                                    salesCss3.layoutParams = params
                                    salesCst3.visibility = View.VISIBLE
                                    salesCs3.visibility = View.VISIBLE
                                    salesCss3.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst4.text = result.data.city_ranking[3].cname
                                    val nubxian = result.data.city_ranking[3].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs4.progress = s.toInt()
                                    salesCss4.text = result.data.city_ranking[3].nums
                                    val params = salesCss4!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1585, 630 - d, 0, 0)
                                    salesCss4.layoutParams = params
                                    salesCst4.visibility = View.VISIBLE
                                    salesCs4.visibility = View.VISIBLE
                                    salesCss4.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst5.text = result.data.city_ranking[4].cname
                                    val nubxian = result.data.city_ranking[4].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs5.progress = s.toInt()
                                    salesCss5.text = result.data.city_ranking[4].nums
                                    val params = salesCss5.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1626, 630 - d, 0, 0)
                                    salesCss5.layoutParams = params
                                    salesCst5.visibility = View.VISIBLE
                                    salesCs5.visibility = View.VISIBLE
                                    salesCss5.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst6!!.text = result.data.city_ranking[5].cname
                                    val nubxian = result.data.city_ranking[5].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs6!!.progress = s.toInt()
                                    salesCss6!!.text = result.data.city_ranking[5].nums
                                    val params = salesCss6!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1664, 630 - d, 0, 0)
                                    salesCss6!!.layoutParams = params
                                    salesCst6!!.visibility = View.VISIBLE
                                    salesCs6!!.visibility = View.VISIBLE
                                    salesCss6!!.visibility = View.VISIBLE
                                }
                                run {
                                    sales_cst7!!.text = result.data.city_ranking[6].cname
                                    val nubxian = result.data.city_ranking[6].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales_cs7!!.progress = s.toInt()
                                    salesCss7.text = result.data.city_ranking[6].nums
                                    val params = salesCss7.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1703, 630 - d, 0, 0)
                                    salesCss7.layoutParams = params
                                    sales_cst7!!.visibility = View.VISIBLE
                                    sales_cs7!!.visibility = View.VISIBLE
                                    salesCss7.visibility = View.VISIBLE
                                }
                            }
                            if (result.data.city_ranking.size == 6) {
                                val max = result.data.city_ranking_max.toInt()
                                run {
                                    salesCst1!!.text = result.data.city_ranking[0].cname
                                    val nubxian = result.data.city_ranking[0].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs1!!.progress = s.toInt()
                                    salesCss1!!.text = result.data.city_ranking[0].nums
                                    val params = salesCss1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1469, 630 - d, 0, 0)
                                    salesCss1!!.layoutParams = params
                                    salesCst1!!.visibility = View.VISIBLE
                                    salesCs1!!.visibility = View.VISIBLE
                                    salesCss1!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst2!!.text = result.data.city_ranking[1].cname
                                    val nubxian = result.data.city_ranking[1].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs2!!.progress = s.toInt()
                                    salesCss2!!.text = result.data.city_ranking[1].nums
                                    val params = salesCss2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1507, 630 - d, 0, 0)
                                    salesCss2!!.layoutParams = params
                                    salesCst2!!.visibility = View.VISIBLE
                                    salesCs2!!.visibility = View.VISIBLE
                                    salesCss2!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst3!!.text = result.data.city_ranking[2].cname
                                    val nubxian = result.data.city_ranking[2].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs3!!.progress = s.toInt()
                                    salesCss3!!.text = result.data.city_ranking[2].nums
                                    val params = salesCss3!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1548, 630 - d, 0, 0)
                                    salesCss3!!.layoutParams = params
                                    salesCst3!!.visibility = View.VISIBLE
                                    salesCs3!!.visibility = View.VISIBLE
                                    salesCss3!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst4!!.text = result.data.city_ranking[3].cname
                                    val nubxian = result.data.city_ranking[3].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs4!!.progress = s.toInt()
                                    salesCss4!!.text = result.data.city_ranking[3].nums
                                    val params = salesCss4!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1585, 630 - d, 0, 0)
                                    salesCss4!!.layoutParams = params
                                    salesCst4!!.visibility = View.VISIBLE
                                    salesCs4!!.visibility = View.VISIBLE
                                    salesCss4!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst5!!.text = result.data.city_ranking[4].cname
                                    val nubxian = result.data.city_ranking[4].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs5!!.progress = s.toInt()
                                    salesCss5!!.text = result.data.city_ranking[4].nums
                                    val params = salesCss5!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1626, 630 - d, 0, 0)
                                    salesCss5!!.layoutParams = params
                                    salesCst5!!.visibility = View.VISIBLE
                                    salesCs5!!.visibility = View.VISIBLE
                                    salesCss5!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst6!!.text = result.data.city_ranking[5].cname
                                    val nubxian = result.data.city_ranking[5].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs6!!.progress = s.toInt()
                                    salesCss6!!.text = result.data.city_ranking[5].nums
                                    val params = salesCss6!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1664, 630 - d, 0, 0)
                                    salesCss6!!.layoutParams = params
                                    salesCst6!!.visibility = View.VISIBLE
                                    salesCs6!!.visibility = View.VISIBLE
                                    salesCss6!!.visibility = View.VISIBLE
                                }
                                run {
                                    sales_cst7!!.visibility = View.GONE
                                    sales_cs7!!.visibility = View.GONE
                                    salesCss7!!.visibility = View.GONE
                                }
                            }
                            if (result.data.city_ranking.size == 5) {
                                val max = result.data.city_ranking_max.toInt()
                                run {
                                    salesCst1!!.text = result.data.city_ranking[0].cname
                                    val nubxian = result.data.city_ranking[0].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs1!!.progress = s.toInt()
                                    salesCss1!!.text = result.data.city_ranking[0].nums
                                    val params = salesCss1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1469, 630 - d, 0, 0)
                                    salesCss1!!.layoutParams = params
                                    salesCst1!!.visibility = View.VISIBLE
                                    salesCs1!!.visibility = View.VISIBLE
                                    salesCss1!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst2!!.text = result.data.city_ranking[1].cname
                                    val nubxian = result.data.city_ranking[1].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs2!!.progress = s.toInt()
                                    salesCss2!!.text = result.data.city_ranking[1].nums
                                    val params = salesCss2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1507, 630 - d, 0, 0)
                                    salesCss2!!.layoutParams = params
                                    salesCst2!!.visibility = View.VISIBLE
                                    salesCs2!!.visibility = View.VISIBLE
                                    salesCss2!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst3!!.text = result.data.city_ranking[2].cname
                                    val nubxian = result.data.city_ranking[2].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs3!!.progress = s.toInt()
                                    salesCss3!!.text = result.data.city_ranking[2].nums
                                    val params = salesCss3!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1548, 630 - d, 0, 0)
                                    salesCss3!!.layoutParams = params
                                    salesCst3!!.visibility = View.VISIBLE
                                    salesCs3!!.visibility = View.VISIBLE
                                    salesCss3!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst4!!.text = result.data.city_ranking[3].cname
                                    val nubxian = result.data.city_ranking[3].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs4!!.progress = s.toInt()
                                    salesCss4!!.text = result.data.city_ranking[3].nums
                                    val params = salesCss4!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1585, 630 - d, 0, 0)
                                    salesCss4!!.layoutParams = params
                                    salesCst4!!.visibility = View.VISIBLE
                                    salesCs4!!.visibility = View.VISIBLE
                                    salesCss4!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst5!!.text = result.data.city_ranking[4].cname
                                    val nubxian = result.data.city_ranking[4].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs5!!.progress = s.toInt()
                                    salesCss5!!.text = result.data.city_ranking[4].nums
                                    val params = salesCss5!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1626, 630 - d, 0, 0)
                                    salesCss5!!.layoutParams = params
                                    salesCst5!!.visibility = View.VISIBLE
                                    salesCs5!!.visibility = View.VISIBLE
                                    salesCss5!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst6!!.visibility = View.GONE
                                    salesCs6!!.visibility = View.GONE
                                    salesCss6!!.visibility = View.GONE
                                }
                                run {
                                    sales_cst7!!.visibility = View.GONE
                                    sales_cs7!!.visibility = View.GONE
                                    salesCss7!!.visibility = View.GONE
                                }
                            }
                            if (result.data.city_ranking.size == 4) {
                                val max = result.data.city_ranking_max.toInt()
                                run {
                                    salesCst1!!.text = result.data.city_ranking[0].cname
                                    val nubxian = result.data.city_ranking[0].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs1!!.progress = s.toInt()
                                    salesCss1!!.text = result.data.city_ranking[0].nums
                                    val params = salesCss1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1469, 630 - d, 0, 0)
                                    salesCss1!!.layoutParams = params
                                    salesCst1!!.visibility = View.VISIBLE
                                    salesCs1!!.visibility = View.VISIBLE
                                    salesCss1!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst2!!.text = result.data.city_ranking[1].cname
                                    val nubxian = result.data.city_ranking[1].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs2!!.progress = s.toInt()
                                    salesCss2!!.text = result.data.city_ranking[1].nums
                                    val params = salesCss2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1507, 630 - d, 0, 0)
                                    salesCss2!!.layoutParams = params
                                    salesCst2!!.visibility = View.VISIBLE
                                    salesCs2!!.visibility = View.VISIBLE
                                    salesCss2!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst3!!.text = result.data.city_ranking[2].cname
                                    val nubxian = result.data.city_ranking[2].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs3!!.progress = s.toInt()
                                    salesCss3!!.text = result.data.city_ranking[2].nums
                                    val params = salesCss3!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1548, 630 - d, 0, 0)
                                    salesCss3!!.layoutParams = params
                                    salesCst3!!.visibility = View.VISIBLE
                                    salesCs3!!.visibility = View.VISIBLE
                                    salesCss3!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst4!!.text = result.data.city_ranking[3].cname
                                    val nubxian = result.data.city_ranking[3].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs4!!.progress = s.toInt()
                                    salesCss4!!.text = result.data.city_ranking[3].nums
                                    val params = salesCss4!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1585, 630 - d, 0, 0)
                                    salesCss4!!.layoutParams = params
                                    salesCst4!!.visibility = View.VISIBLE
                                    salesCs4!!.visibility = View.VISIBLE
                                    salesCss4!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst5!!.visibility = View.GONE
                                    salesCs5!!.visibility = View.GONE
                                    salesCss5!!.visibility = View.GONE
                                }
                                run {
                                    salesCst6!!.visibility = View.GONE
                                    salesCs6!!.visibility = View.GONE
                                    salesCss6!!.visibility = View.GONE
                                }
                                run {
                                    sales_cst7!!.visibility = View.GONE
                                    sales_cs7!!.visibility = View.GONE
                                    salesCss7!!.visibility = View.GONE
                                }
                            }
                            if (result.data.city_ranking.size == 3) {
                                val max = result.data.city_ranking_max.toInt()
                                run {
                                    salesCst1!!.text = result.data.city_ranking[0].cname
                                    val nubxian = result.data.city_ranking[0].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs1!!.progress = s.toInt()
                                    salesCss1!!.text = result.data.city_ranking[0].nums
                                    val params = salesCss1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1469, 630 - d, 0, 0)
                                    salesCss1!!.layoutParams = params
                                    salesCst1!!.visibility = View.VISIBLE
                                    salesCs1!!.visibility = View.VISIBLE
                                    salesCss1!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst2!!.text = result.data.city_ranking[1].cname
                                    val nubxian = result.data.city_ranking[1].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs2!!.progress = s.toInt()
                                    salesCss2!!.text = result.data.city_ranking[1].nums
                                    val params = salesCss2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1507, 630 - d, 0, 0)
                                    salesCss2!!.layoutParams = params
                                    salesCst2!!.visibility = View.VISIBLE
                                    salesCs2!!.visibility = View.VISIBLE
                                    salesCss2!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst3!!.text = result.data.city_ranking[2].cname
                                    val nubxian = result.data.city_ranking[2].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs3!!.progress = s.toInt()
                                    salesCss3!!.text = result.data.city_ranking[2].nums
                                    val params = salesCss3!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1548, 630 - d, 0, 0)
                                    salesCss3!!.layoutParams = params
                                    salesCst3!!.visibility = View.VISIBLE
                                    salesCs3!!.visibility = View.VISIBLE
                                    salesCss3!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst4!!.visibility = View.GONE
                                    salesCs4!!.visibility = View.GONE
                                    salesCss4!!.visibility = View.GONE
                                }
                                run {
                                    salesCst5!!.visibility = View.GONE
                                    salesCs5!!.visibility = View.GONE
                                    salesCss5!!.visibility = View.GONE
                                }
                                run {
                                    salesCst6!!.visibility = View.GONE
                                    salesCs6!!.visibility = View.GONE
                                    salesCss6!!.visibility = View.GONE
                                }
                                run {
                                    sales_cst7!!.visibility = View.GONE
                                    sales_cs7!!.visibility = View.GONE
                                    salesCss7!!.visibility = View.GONE
                                }
                            }
                            if (result.data.city_ranking.size == 2) {
                                val max = result.data.city_ranking_max.toInt()
                                run {
                                    salesCst1!!.text = result.data.city_ranking[0].cname
                                    val nubxian = result.data.city_ranking[0].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs1!!.progress = s.toInt()
                                    salesCss1!!.text = result.data.city_ranking[0].nums
                                    val params = salesCss1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1469, 630 - d, 0, 0)
                                    salesCss1!!.layoutParams = params
                                    salesCst1!!.visibility = View.VISIBLE
                                    salesCs1!!.visibility = View.VISIBLE
                                    salesCss1!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst2!!.text = result.data.city_ranking[1].cname
                                    val nubxian = result.data.city_ranking[1].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs2!!.progress = s.toInt()
                                    salesCss2!!.text = result.data.city_ranking[1].nums
                                    val params = salesCss2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1507, 630 - d, 0, 0)
                                    salesCss2!!.layoutParams = params
                                    salesCst2!!.visibility = View.VISIBLE
                                    salesCs2!!.visibility = View.VISIBLE
                                    salesCss2!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst3!!.visibility = View.GONE
                                    salesCs3!!.visibility = View.GONE
                                    salesCss3!!.visibility = View.GONE
                                }
                                run {
                                    salesCst4!!.visibility = View.GONE
                                    salesCs4!!.visibility = View.GONE
                                    salesCss4!!.visibility = View.GONE
                                }
                                run {
                                    salesCst5!!.visibility = View.GONE
                                    salesCs5!!.visibility = View.GONE
                                    salesCss5!!.visibility = View.GONE
                                }
                                run {
                                    salesCst6!!.visibility = View.GONE
                                    salesCs6!!.visibility = View.GONE
                                    salesCss6!!.visibility = View.GONE
                                }
                                run {
                                    sales_cst7!!.visibility = View.GONE
                                    sales_cs7!!.visibility = View.GONE
                                    salesCss7!!.visibility = View.GONE
                                }
                            }
                            if (result.data.city_ranking.size == 1) {
                                val max = result.data.city_ranking_max.toInt()
                                run {
                                    salesCst1!!.text = result.data.city_ranking[0].cname
                                    val nubxian = result.data.city_ranking[0].nums.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    salesCs1!!.progress = s.toInt()
                                    salesCss1!!.text = result.data.city_ranking[0].nums
                                    val params = salesCss1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 135 / 100
                                    params.setMargins(1469, 630 - d, 0, 0)
                                    salesCss1!!.layoutParams = params
                                    salesCst1!!.visibility = View.VISIBLE
                                    salesCs1!!.visibility = View.VISIBLE
                                    salesCss1!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesCst2!!.visibility = View.GONE
                                    salesCs2!!.visibility = View.GONE
                                    salesCss2!!.visibility = View.GONE
                                }
                                run {
                                    salesCst3!!.visibility = View.GONE
                                    salesCs3!!.visibility = View.GONE
                                    salesCss3!!.visibility = View.GONE
                                }
                                run {
                                    salesCst4!!.visibility = View.GONE
                                    salesCs4!!.visibility = View.GONE
                                    salesCss4!!.visibility = View.GONE
                                }
                                run {
                                    salesCst5!!.visibility = View.GONE
                                    salesCs5!!.visibility = View.GONE
                                    salesCss5!!.visibility = View.GONE
                                }
                                run {
                                    salesCst6!!.visibility = View.GONE
                                    salesCs6!!.visibility = View.GONE
                                    salesCss6!!.visibility = View.GONE
                                }
                                run {
                                    sales_cst7!!.visibility = View.GONE
                                    sales_cs7!!.visibility = View.GONE
                                    salesCss7!!.visibility = View.GONE
                                }
                            }
                            if (result.data.city_ranking.size == 0) {
                                run {
                                    salesCst1!!.visibility = View.GONE
                                    salesCs1!!.visibility = View.GONE
                                    salesCss1!!.visibility = View.GONE
                                }
                                run {
                                    salesCst2!!.visibility = View.GONE
                                    salesCs2!!.visibility = View.GONE
                                    salesCss2!!.visibility = View.GONE
                                }
                                run {
                                    salesCst3!!.visibility = View.GONE
                                    salesCs3!!.visibility = View.GONE
                                    salesCss3!!.visibility = View.GONE
                                }
                                run {
                                    salesCst4!!.visibility = View.GONE
                                    salesCs4!!.visibility = View.GONE
                                    salesCss4!!.visibility = View.GONE
                                }
                                run {
                                    salesCst5!!.visibility = View.GONE
                                    salesCs5!!.visibility = View.GONE
                                    salesCss5!!.visibility = View.GONE
                                }
                                run {
                                    salesCst6!!.visibility = View.GONE
                                    salesCs6!!.visibility = View.GONE
                                    salesCss6!!.visibility = View.GONE
                                }
                                run {
                                    sales_cst7!!.visibility = View.GONE
                                    sales_cs7!!.visibility = View.GONE
                                    salesCss7!!.visibility = View.GONE
                                }
                            }

                            //产品排行
                            if (result.data.product_category_ranking.size == 5) {
                                val max = result.data.product_category_ranking_max.toInt()
                                run {
                                    salesN1!!.text = result.data.product_category_ranking[0].goods_line_name
                                    val nubxian = result.data.product_category_ranking[0].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales1!!.progress = s.toInt()
                                    salesT1!!.text = result.data.product_category_ranking[0].goods_number
                                    val params = salesT1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 616, 0, 0)
                                    salesT1!!.layoutParams = params
                                }
                                run {
                                    salesN2!!.text = result.data.product_category_ranking[1].goods_line_name
                                    val nubxian = result.data.product_category_ranking[1].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales2!!.progress = s.toInt()
                                    salesT2!!.text = result.data.product_category_ranking[1].goods_number
                                    val params = salesT2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 586, 0, 0)
                                    salesT2!!.layoutParams = params
                                }
                                run {
                                    salesN3!!.text = result.data.product_category_ranking[2].goods_line_name
                                    val nubxian = result.data.product_category_ranking[2].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales3!!.progress = s.toInt()
                                    salesT3!!.text = result.data.product_category_ranking[2].goods_number
                                    val params = salesT3!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 557, 0, 0)
                                    salesT3!!.layoutParams = params
                                }
                                run {
                                    salesN4!!.text = result.data.product_category_ranking[3].goods_line_name
                                    val nubxian = result.data.product_category_ranking[3].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales4!!.progress = s.toInt()
                                    salesT4!!.text = result.data.product_category_ranking[3].goods_number
                                    val params = salesT4!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 528, 0, 0)
                                    salesT4!!.layoutParams = params
                                    salesN4!!.visibility = View.VISIBLE
                                    sales4!!.visibility = View.VISIBLE
                                    salesT4!!.visibility = View.VISIBLE
                                }
                                run {
                                    salesN5!!.text = result.data.product_category_ranking[4].goods_line_name
                                    val nubxian = result.data.product_category_ranking[4].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales5!!.progress = s.toInt()
                                    salesT5!!.text = result.data.product_category_ranking[4].goods_number
                                    val params = salesT5!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 497, 0, 0)
                                    salesT5!!.layoutParams = params
                                    salesN5!!.visibility = View.VISIBLE
                                    sales5!!.visibility = View.VISIBLE
                                    salesT5!!.visibility = View.VISIBLE
                                }
                            }
                            if (result.data.product_category_ranking.size == 4) {
                                val max = result.data.product_category_ranking_max.toInt()
                                run {
                                    salesN1!!.text = result.data.product_category_ranking[0].goods_line_name
                                    val nubxian = result.data.product_category_ranking[0].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales1!!.progress = s.toInt()
                                    salesT1!!.text = result.data.product_category_ranking[0].goods_number
                                    val params = salesT1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 616, 0, 0)
                                    salesT1!!.layoutParams = params
                                }
                                run {
                                    salesN2!!.text = result.data.product_category_ranking[1].goods_line_name
                                    val nubxian = result.data.product_category_ranking[1].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales2!!.progress = s.toInt()
                                    salesT2!!.text = result.data.product_category_ranking[1].goods_number
                                    val params = salesT2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 586, 0, 0)
                                    Log.i("Qqqq", "getSales: " + d + 1046)
                                    salesT2!!.layoutParams = params
                                }
                                run {
                                    salesN3!!.text = result.data.product_category_ranking[2].goods_line_name
                                    val nubxian = result.data.product_category_ranking[2].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales3!!.progress = s.toInt()
                                    salesT3!!.text = result.data.product_category_ranking[2].goods_number
                                    val params = salesT3!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 557, 0, 0)
                                    salesT3!!.layoutParams = params
                                }
                                run {
                                    salesN4!!.text = result.data.product_category_ranking[3].goods_line_name
                                    val nubxian = result.data.product_category_ranking[3].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales4!!.progress = s.toInt()
                                    salesT4!!.text = result.data.product_category_ranking[3].goods_number
                                    val params = salesT4!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 528, 0, 0)
                                    salesT4!!.layoutParams = params
                                    salesN4!!.visibility = View.VISIBLE
                                    sales4!!.visibility = View.VISIBLE
                                    salesT4!!.visibility = View.VISIBLE
                                    salesN5!!.visibility = View.GONE
                                    sales5!!.visibility = View.GONE
                                    salesT5!!.visibility = View.GONE
                                }
                            }
                            if (result.data.product_category_ranking.size == 3) {
                                val max = result.data.product_category_ranking_max.toInt()
                                run {
                                    salesN1!!.text = result.data.product_category_ranking[0].goods_line_name
                                    val nubxian = result.data.product_category_ranking[0].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales1!!.progress = s.toInt()
                                    salesT1!!.text = result.data.product_category_ranking[0].goods_number
                                    val params = salesT1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 616, 0, 0)
                                    salesT1!!.layoutParams = params
                                }
                                run {
                                    salesN2!!.text = result.data.product_category_ranking[1].goods_line_name
                                    val nubxian = result.data.product_category_ranking[1].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales2!!.progress = s.toInt()
                                    salesT2!!.text = result.data.product_category_ranking[1].goods_number
                                    val params = salesT2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 586, 0, 0)
                                    Log.i("Qqqq", "getSales: " + d + 1046)
                                    salesT2!!.layoutParams = params
                                }
                                run {
                                    salesN3!!.text = result.data.product_category_ranking[2].goods_line_name
                                    val nubxian = result.data.product_category_ranking[2].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales3!!.progress = s.toInt()
                                    salesT3!!.text = result.data.product_category_ranking[2].goods_number
                                    val params = salesT3!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 557, 0, 0)
                                    salesT3!!.layoutParams = params
                                    salesN4!!.visibility = View.GONE
                                    sales4!!.visibility = View.GONE
                                    salesT4!!.visibility = View.GONE
                                    salesN5!!.visibility = View.GONE
                                    sales5!!.visibility = View.GONE
                                    salesT5!!.visibility = View.GONE
                                }
                            }
                            if (result.data.product_category_ranking.size == 2) {
                                val max = result.data.product_category_ranking_max.toInt()
                                run {
                                    salesN1!!.text = result.data.product_category_ranking[0].goods_line_name
                                    val nubxian = result.data.product_category_ranking[0].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales1!!.progress = s.toInt()
                                    salesT1!!.text = result.data.product_category_ranking[0].goods_number
                                    val params = salesT1!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 616, 0, 0)
                                    salesT1!!.layoutParams = params
                                }
                                run {
                                    salesN2!!.text = result.data.product_category_ranking[1].goods_line_name
                                    val nubxian = result.data.product_category_ranking[1].goods_number.toInt()
                                    val s = 100 * div(nubxian.toDouble(), max.toDouble(), 2)
                                    sales2!!.progress = s.toInt()
                                    salesT2!!.text = result.data.product_category_ranking[1].goods_number
                                    val params = salesT2!!.layoutParams as LinearLayout.LayoutParams
                                    val d = s.toInt() * 2
                                    params.setMargins(d + 1046, 586, 0, 0)
                                    Log.i("Qqqq", "getSales: " + d + 1046)
                                    salesT2!!.layoutParams = params
                                    salesN3!!.visibility = View.GONE
                                    sales3!!.visibility = View.GONE
                                    salesT3!!.visibility = View.GONE
                                    salesN4!!.visibility = View.GONE
                                    sales4!!.visibility = View.GONE
                                    salesT4!!.visibility = View.GONE
                                    salesN5!!.visibility = View.GONE
                                    sales5!!.visibility = View.GONE
                                    salesT5!!.visibility = View.GONE
                                }

                            }


                            //地图
                            list.clear()
                            list.addAll(result.data.sales_region)
                            //销售总额
                            val amount = result.data.all_sales.all_amount
                            if (amount.length == 9) {
                                text0!!.text = amount[0].toString()
                                text1!!.text = amount[1].toString()
                                text2!!.text = amount[2].toString()
                                text3!!.text = amount[3].toString()
                                text4!!.text = amount[4].toString()
                                text5!!.text = amount[5].toString()
                                text6!!.text = amount[6].toString()
                                text7!!.text = amount[7].toString()
                                text8!!.text = amount[8].toString()
                            }
                            if (amount.length == 8) {
                                text0!!.text = "0"
                                text1!!.text = amount[0].toString()
                                text2!!.text = amount[1].toString()
                                text3!!.text = amount[2].toString()
                                text4!!.text = amount[3].toString()
                                text5!!.text = amount[4].toString()
                                text6!!.text = amount[5].toString()
                                text7!!.text = amount[6].toString()
                                text8!!.text = amount[7].toString()
                            }
                            if (amount.length == 7) {
                                text0!!.text = "0"
                                text1!!.text = "0"
                                text2!!.text = amount[0].toString()
                                text3!!.text = amount[1].toString()
                                text4!!.text = amount[2].toString()
                                text5!!.text = amount[3].toString()
                                text6!!.text = amount[4].toString()
                                text7!!.text = amount[5].toString()
                                text8!!.text = amount[6].toString()
                            }
                            if (amount.length == 6) {
                                text0!!.text = "0"
                                text1!!.text = "0"
                                text2!!.text = "0"
                                text3!!.text = amount[0].toString()
                                text4!!.text = amount[1].toString()
                                text5!!.text = amount[2].toString()
                                text6!!.text = amount[3].toString()
                                text7!!.text = amount[4].toString()
                                text8!!.text = amount[5].toString()
                            }
                            if (amount.length == 5) {
                                text0!!.text = "0"
                                text1!!.text = "0"
                                text2!!.text = "0"
                                text3!!.text = "0"
                                text4!!.text = amount[0].toString()
                                text5!!.text = amount[1].toString()
                                text6!!.text = amount[2].toString()
                                text7!!.text = amount[3].toString()
                                text8!!.text = amount[4].toString()
                            }
                            if (amount.length == 4) {
                                text0!!.text = "0"
                                text1!!.text = "0"
                                text2!!.text = "0"
                                text3!!.text = "0"
                                text4!!.text = "0"
                                text5!!.text = amount[0].toString()
                                text6!!.text = amount[1].toString()
                                text7!!.text = amount[2].toString()
                                text8!!.text = amount[3].toString()
                            }
                            if (amount.length == 3) {
                                text0!!.text = "0"
                                text1!!.text = "0"
                                text2!!.text = "0"
                                text3!!.text = "0"
                                text4!!.text = "0"
                                text5!!.text = "0"
                                text6!!.text = amount[0].toString()
                                text7!!.text = amount[1].toString()
                                text8!!.text = amount[2].toString()
                            }
                            if (amount.length == 2) {
                                text0!!.text = "0"
                                text1!!.text = "0"
                                text2!!.text = "0"
                                text3!!.text = "0"
                                text4!!.text = "0"
                                text5!!.text = "0"
                                text6!!.text = "0"
                                text7!!.text = amount[0].toString()
                                text8!!.text = amount[1].toString()
                            }
                            if (amount.length == 1) {
                                text0!!.text = "0"
                                text1!!.text = "0"
                                text2!!.text = "0"
                                text3!!.text = "0"
                                text4!!.text = "0"
                                text5!!.text = "0"
                                text6!!.text = "0"
                                text7!!.text = "0"
                                text8!!.text = amount[0].toString()
                            }
                            order1!!.text = result.data.all_sales.today_order_count
                            order2!!.text = result.data.all_sales.today_order_amount
                            order3!!.text = result.data.all_sales.month_order_count
                            order4!!.text = result.data.all_sales.month_order_amount
                            time!!.text = "截止时间：" + result.data.last_time
                            //年度目标
                            quarter_order_price!!.text = result.data.year_target.quarter_order_price + " "
//                            if (result.data.year_target.growth_status == "0") {
//                                growth_status!!.setImageResource(R.drawable.img_1)
//                            } else {
//                                growth_status!!.setImageResource(R.drawable.img_2)
//                            }
//                            rate!!.text = result.data.year_target.quarter_grown.toString() + "%"
                            val d = result.data.year_target.year_target_rate.toInt()
                            sales_cpv!!.progress = d
                            sales_cpv!!.runProgressAnim(1000)

                            //分类明细
                            Log.i("qwq", "getSales: $codeMix")
                            codeXian = 0
                            val a = result.data.product_details[0].rate
                            salesC!!.progress = a
                            salesC!!.runProgressAnim(1000)
                            sales_pb!!.progress = result.data.product_details[0].quarter_rate
                            salesQ!!.text = result.data.product_details[0].quarter_rate.toString() + "%"
                            salesQq!!.text = result.data.product_details[0].goods_number + ""
                            salesQw!!.text = result.data.product_details[0].amount + ""
                            salesQe!!.text = result.data.product_details[0].goods_line_name + ""
                            //地图
                            val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
                            sales_rec!!.layoutManager = linearLayoutManager
                            val adapter = SalesAdapter(R.layout.item_sales, result.data.product_details)
                            sales_rec!!.adapter = adapter
                            adapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { adapter1: BaseQuickAdapter<*, *>?, view: View?, position: Int ->
                                val a1 = result.data.product_details[position].rate
                                salesC!!.progress = a1
                                salesC!!.runProgressAnim(1000)
                                sales_pb!!.progress = result.data.product_details[position].quarter_rate
                                salesQ!!.text = result.data.product_details[position].quarter_rate.toString() + "%"
                                salesQq!!.text = result.data.product_details[position].goods_number + ""
                                salesQw!!.text = result.data.product_details[position].amount + ""
                                salesQe!!.text = result.data.product_details[position].goods_line_name + ""
                                sales_rec!!.visibility = View.GONE
                                sales_imp!!.setImageResource(R.drawable.sales_2)
                            }
//                            line_3.text = result.data.ytD_product_chart_line.get(0).line_name
                            line_2.text = result.data.ytD_product_chart_line.get(0).line_name
                            line_1.text = result.data.ytD_product_chart_line.get(1).line_name

                        } else {
                            ResultCheckUtils().checkResult(mContext, result.code, result.msg)
                        }
                    }
                    ) { e: Throwable -> LogUtils.showLog(HttpManager.TAG, e.message) }
        }


    fun div(v1: Double, v2: Double, scale: Int): Double {
        require(scale >= 0) { "The scale must be a positive integer or zero" }
        val b1 = BigDecimal(java.lang.Double.toString(v1))
        val b2 = BigDecimal(java.lang.Double.toString(v2))
        return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).toDouble()

    }

    //X轴展示内容
    private fun getXValues(list: ArrayList<SalesBean.DataBean.YtdBean>): List<AxisValue>
    {

        val listAxisXValues = ArrayList<AxisValue>()

        listAxisXValues.add(AxisValue(0.toFloat()).setLabel(list[0].months ))
        listAxisXValues.add(AxisValue(1.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(2.toFloat()).setLabel(list[1].months ))
        listAxisXValues.add(AxisValue(3.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(4.toFloat()).setLabel(list[2].months ))
        listAxisXValues.add(AxisValue(5.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(6.toFloat()).setLabel(list[3].months ))
        listAxisXValues.add(AxisValue(7.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(8.toFloat()).setLabel(list[4].months ))
        listAxisXValues.add(AxisValue(9.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(10.toFloat()).setLabel(list[5].months ))

//
//        //设置X轴显示
//        for (i in list.indices)
//        {
//            if(i%2==0){
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(list[i].months ))
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(""))
//            }else{
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(list[i].months ))
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(""))
//            }
//        }


        return listAxisXValues
    }
    //Y轴展示内容
    private fun getYValues(maxYValue: Float, isHarPer: Boolean): List<AxisValue>
    {
        val listAxisYValues = ArrayList<AxisValue>()
        var per = 10

        when
        {
            maxYValue > 0 && maxYValue <= 50 -> per = 5
            maxYValue > 50 && maxYValue <= 100 -> per = 10
            maxYValue > 100 && maxYValue <= 500 -> per = 50
            maxYValue > 500 && maxYValue <= 1000 -> per = 100
            maxYValue > 1000 && maxYValue <= 5000 -> per = 250
            maxYValue > 5000 && maxYValue <= 10000 -> per = 500
            maxYValue > 10000 -> per = 1000
        }

        //设置Y轴显示
        var i = 0
        while (i <= maxYValue)
        {
            i += if (isHarPer && maxYValue > 0)
            {
//                listAxisYValues.add(AxisValue(i.toFloat())
//                        .setLabel("${formatPer(i * 100 / maxYValue)}%"))
                listAxisYValues.add(AxisValue(i.toFloat()).setLabel(i.toString()))
                per
            }
            else
            {
                listAxisYValues.add(AxisValue(i.toFloat()).setLabel(i.toString()))

                per
            }
        }

        return listAxisYValues
    }
    private fun formatPer(per: Float): Int
    {
        return when
        {
            per > 0 && per <= 7 -> 5
            per > 7 && per <= 12 -> 10
            per > 12 && per <= 17 -> 15
            per > 17 && per <= 22 -> 20
            per > 22 && per <= 27 -> 25
            per > 27 && per <= 32 -> 30
            per > 32 && per <= 37 -> 35
            per > 37 && per <= 42 -> 40
            per > 42 && per <= 47 -> 45
            per > 47 && per <= 52 -> 50
            per > 52 && per <= 57 -> 55
            per > 57 && per <= 62 -> 60
            per > 62 && per <= 67 -> 65
            per > 67 && per <= 72 -> 70
            per > 72 && per <= 77 -> 75
            per > 77 && per <= 82 -> 80
            per > 82 && per <= 87 -> 85
            per > 87 && per <= 92 -> 90
            per > 92 && per <= 97 -> 95
            per > 97 && per <= 100 -> 100
            else -> 0
        }
    }

    //X轴
    private fun getXAxis(list: ArrayList<SalesBean.DataBean.YtdBean>): Axis
    {
        //X轴
        val axisX = Axis()
        //X轴标注
        //        axisX.setName("X轴");
        //设置字体颜色
        axisX.textColor = Color.parseColor("#748ebf")
        //设置字体大小
        axisX.textSize = 4
        //是否有分割线
        axisX.setHasLines(false)
        //X坐标轴字体是否斜体
        axisX.setHasTiltedLabels(false)
        //填充X轴的坐标名称
        axisX.values = getXValues(list)
        //设置轴标签和名字的字体
        //        axisX.setTypeface(Typeface typeface);
        //设置轴标签可显示的最大字符个数，范围在0-32之间
        //        axisX.setMaxLabelChars(5);
        //设置是否自动生成轴对象，自动适应表格的范围
        axisX.isAutoGenerated = false
        //设置是否将轴坐标的值显示在图表内侧
        axisX.isInside = false

        return axisX
    }
    //Y轴
    private fun getYAxis(maxYValue: Float, isHasPer: Boolean): Axis
    {
        //Y轴(不设置setValues会根据数据的大小自动设置Y轴上限)
        val axisY = Axis()
        //Y轴标注
        //        axisY.setName("Y轴");
        //设置字体颜色748ebf
        axisY.textColor = Color.parseColor("#748ebf")
        //设置字体大小
        axisY.textSize = 5
        //是否有分割线
        axisY.setHasLines(true)
        axisY.lineColor = Color.parseColor("#308EE3FF")
        //Y坐标轴字体是否斜体
        axisY.setHasTiltedLabels(false)
        //填充Y轴的坐标名称
        axisY.values = getYValues(maxYValue, isHasPer)
        //设置轴标签和名字的字体
        //        axisY.setTypeface(Typeface typeface);
        //设置轴标签可显示的最大字符个数，范围在0-32之间
        axisY.maxLabelChars = 10
        //设置是否自动生成轴对象，自动适应表格的范围
        axisY.isAutoGenerated = false
        //设置是否将轴坐标的值显示在图表内侧
        axisY.isInside = false

        return axisY
    }

    //添加柱

    private fun addColumn(data: SalesBean.DataBean.YtdBean, isShow: Boolean, order_num:String, active_num:String,line:String): Column
    {
        var order_nums = ""
        var active_nums = ""
        var line_1 = ""
        if (isShow){
            order_nums=order_num
            active_nums=active_num
            line_1 =line
        }
        val listColumnValue = ArrayList<SubcolumnValue>()
//        listColumnValue.add(SubcolumnValue(data.line_1.toFloat(),
//                if (isShow) Color.parseColor("#00B67C") else
//                    Color.parseColor("#00000000"))
//                .setLabel(order_nums))

        listColumnValue.add(SubcolumnValue(data.line_2.toFloat(),
                if (isShow) Color.parseColor("#029BE8")else
                    Color.parseColor("#00000000"))
                .setLabel(active_nums))

        listColumnValue.add(SubcolumnValue(data.line_3.toFloat(),
                if (isShow) Color.parseColor("#E5981F")else
                    Color.parseColor("#00000000"))
                .setLabel(line_1))

        //柱
        val column = Column(listColumnValue)
        //柱的数据坐标是否加上备注
        column.setHasLabels(true)
        //点击数据坐标提示数据（设置column.setHasLabels(true);就无效）
//        column.setHasLabelsOnlyForSelected(true)

        return column
    }
    private fun initComboLineColumnChartView(list: ArrayList<SalesBean.DataBean.YtdBean>)
    {
        var maxYValue = 0f
        var cMaxYValue = 0f
        var lMaxYValue = 0f
        var setPer = 1f

        for (data in list)
        {
//            if (data.line_1.toFloat() > cMaxYValue)
//            {
//                cMaxYValue = data.line_1.toFloat()
//            }

            if (data.line_2.toFloat() > cMaxYValue)
            {
                cMaxYValue = data.line_2.toFloat()
            }
            if (data.line_3.toFloat() > cMaxYValue)
            {
                cMaxYValue = data.line_3.toFloat()
            }

        }

        maxYValue = cMaxYValue
        setPer = cMaxYValue / lMaxYValue

        LogUtils.showLog("tables", "maxYValue=$maxYValue-cMaxYValue=$cMaxYValue-lMaxYValue=$lMaxYValue-setPer=$setPer")

        //设置线数据
        val listLine = ArrayList<Line>()
        listLine.add(addLine(list, setPer,"3"))
        listLine.add(addLine(list, setPer,"2"))
//        listLine.add(addLine(list, setPer,"3"))
        val lineChartData = LineChartData()
        lineChartData.lines = listLine

        //设置柱状图数据
        val listColumn = ArrayList<Column>()
        for (i in list.indices)
        {
            if (i==list.size-1){
                listColumn.add(addColumn(list[i],true,"","",""))
                listColumn.add(addColumn(list[i],false,"","",""))
            }else{
                listColumn.add(addColumn(list[i],true,"","",""))
                listColumn.add(addColumn(list[i],false,"","",""))
            }
        }

        val columnChartData = ColumnChartData()
        columnChartData.columns = listColumn

        ////////////////
        //给图表设置数据
        val comboLineColumnChartData = ComboLineColumnChartData()
        comboLineColumnChartData.lineChartData = lineChartData
        comboLineColumnChartData.columnChartData = columnChartData

        //设置标签背景颜色
        comboLineColumnChartData.valueLabelBackgroundColor = resources.getColor(R.color.transparent)
        //设置是否自动绘制标签背景
        comboLineColumnChartData.isValueLabelBackgroundAuto = false
        //设置标签文字颜色，默认为白色
        comboLineColumnChartData.setValueLabelsTextColor(Color.parseColor("#748ebf"))
        //设置标签文字字号，默认为12sp
        comboLineColumnChartData.valueLabelTextSize = 5

        //X轴在底部
        comboLineColumnChartData.axisXBottom = getXAxis(list)
        //Y轴设置在左边
        comboLineColumnChartData.axisYLeft = getYAxis(maxYValue, false)
//        //Y轴设置在右边
//        comboLineColumnChartData.axisYRight = getYAxis(maxYValue, true)
        frg_trs_ccv_clccv_tra.comboLineColumnChartData = comboLineColumnChartData

        //设置图表是可以交互的（拖拽，缩放等效果的前提）
        frg_trs_ccv_clccv_tra.isInteractive = false

        when
        {
            maxYValue > 0 && maxYValue <= 25 -> maxYValue += 5
            maxYValue > 25 && maxYValue <= 50 -> maxYValue += 10
            maxYValue > 50 && maxYValue <= 100 -> maxYValue += 20
            maxYValue > 100 && maxYValue <= 250 -> maxYValue += 50
            maxYValue > 250 && maxYValue <= 500 -> maxYValue += 100
            maxYValue > 500 && maxYValue <= 1000 -> maxYValue += 200
            maxYValue > 1000 && maxYValue <= 5000 -> maxYValue += 1000
            maxYValue > 5000 && maxYValue <= 10000 -> maxYValue += 2000
            maxYValue > 10000 && maxYValue <= 50000 -> maxYValue += 10000
            maxYValue > 50000 && maxYValue <= 100000 -> maxYValue += 25000
            maxYValue > 100000 && maxYValue <= 250000 -> maxYValue += 50000
            maxYValue > 250000 -> maxYValue += 100000
        }

        //设置坐标轴的范围(left-1,right+1可以使X轴坐标前后有空间)
        val viewport = Viewport(-1f, maxYValue, getXValues(list).size.toFloat(), 0f)

        frg_trs_ccv_clccv_tra.maximumViewport = viewport
        frg_trs_ccv_clccv_tra.currentViewport = viewport
    }

    //添加线
    private fun addLine(list: ArrayList<SalesBean.DataBean.YtdBean>, linePer: Float,line: String): Line
    {
        var colorLine = ""
        val listPointValue = ArrayList<PointValue>()

//        //设置图表数据点显示
//        for (i in list.indices)
//        {
//            listPointValue.add(PointValue(i.toFloat(), list[i].active_rate.toInt() * linePer)
//                    .setLabel(""))
////                    .setLabel("${list[i].active_rate.toInt()}%"))
//        }
        if (line.equals("1")){
            listPointValue.add(PointValue(0.toFloat(), list[0].line_1.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(2.toFloat(), list[1].line_1.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(4.toFloat(), list[2].line_1.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(6.toFloat(), list[3].line_1.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(8.toFloat(), list[4].line_1.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(10.toFloat(), list[5].line_1.toInt() * 1f)
                    .setLabel(""))
            colorLine ="#00B67C"
        }else if (line.equals("2")){
            listPointValue.add(PointValue(0.toFloat(), list[0].line_2.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(2.toFloat(), list[1].line_2.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(4.toFloat(), list[2].line_2.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(6.toFloat(), list[3].line_2.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(8.toFloat(), list[4].line_2.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(10.toFloat(), list[5].line_2.toInt() * 1f)
                    .setLabel(""))
            colorLine ="#029BE8"
        }else if (line.equals("3")){
            listPointValue.add(PointValue(0.toFloat(), list[0].line_3.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(2.toFloat(), list[1].line_3.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(4.toFloat(), list[2].line_3.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(6.toFloat(), list[3].line_3.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(8.toFloat(), list[4].line_3.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(10.toFloat(), list[5].line_3.toInt() * 1f)
                    .setLabel(""))
            colorLine ="#FFE5981F"
        }

        //折线
        val line = Line(listPointValue)
        //是否用线显示 如果为false 则没有曲线只有点显示
        line.setHasLines(true)
        //折线颜色
        line.color = Color.parseColor(colorLine)
        //折线粗细
        line.strokeWidth = 1
        //是否有数据点
        line.setHasPoints(true)
        //数据点大小
        line.pointRadius = 1
        //数据点颜色
        line.pointColor = Color.parseColor(colorLine)
        //折线上每个数据点形状(CIRCLE SQUARE DIAMOND)
        line.shape = ValueShape.CIRCLE
        //是否平滑
        line.isCubic = true
        //是否填充曲线的面积
        line.isFilled = false
        //曲线的数据坐标是否加上备注
        line.setHasLabels(true)
        //点击数据坐标提示数据（设置line.setHasLabels(true);就无效）
        //      line.setHasLabelsOnlyForSelected(true);

        return line
    }
}